import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
} from '@nestjs/common';
import ExamSubjectService from '../service/ExamSubjectService';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Log } from 'src/common/decorator/LogDecorator';
import BusinessType from 'src/common/enum/BusinessType';
import ExamSubjectDto from '../dto/ExamSubjectDto';
import { R } from 'src/common/R';
import ExamSubjectVo from '../vo/ExamSubjectVo';

/*
 * @Author: jingfuu@163.com
 * @Date: 2024-12-16 14:14:38
 * @LastEditTime: 2024-12-16 14:34:06
 * @Description: 考试科目接口
 */
@Controller('exam/subject')
@ApiTags('考试科目接口')
class ExamSubjectController {
  constructor(private examSubjectService: ExamSubjectService) {}

  @Get('list-all')
  async listAll(): Promise<R<ExamSubjectVo[]>> {
    const list = await this.examSubjectService.listAll();
    return R.ok(list);
  }

  @ApiOperation({ summary: '新增考试科目' })
  @Log({
    title: '考试科目',
    businessType: BusinessType.INSERT,
  })
  @Post()
  async add(@Body() data: ExamSubjectDto): Promise<R<void>> {
    await this.examSubjectService.add(data);
    return R.ok();
  }

  @ApiOperation({ summary: '修改考试科目' })
  @Log({
    title: '考试科目',
    businessType: BusinessType.UPDATE,
  })
  @Put()
  async modifyExamDistrict(@Body() data: ExamSubjectDto): Promise<R<void>> {
    await this.examSubjectService.edit(data);
    return R.ok();
  }

  @ApiOperation({ summary: '删除考试科目' })
  @Log({
    title: '考试科目',
    businessType: BusinessType.DELETE,
  })
  @Delete('/:id')
  async remove(@Param('id') id: string): Promise<R<any>> {
    if (id.indexOf(',') > -1) {
      for (const item of id.split(',')) {
        await this.examSubjectService.remove(Number.parseInt(item));
      }
    } else {
      await this.examSubjectService.remove(Number.parseInt(id));
    }
    return R.ok();
  }
}
export default ExamSubjectController;
